<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>首页</title>
  <style>
    *,
    *::after,
    *::before {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    :root {
      min-height: 100vh;
    }

    :root:focus-within {
      scroll-behavior: smooth;
    }

    body {
      min-height: inherit;
    }
  </style>
</head>

<body>
  <div></div>
</body>
<script>
  "use strict"; {
    // https://ask.dcloud.net.cn/article/35667
    onLaunch(() => {
      // #ifdef APP-PLUS  
      plus.runtime.getProperty(plus.runtime.appid, ({ version, name } = widgetInfo) => {
        uni.request({
          url: 'http://www.example.com/update/',
          data: { version, name },
          success: (result) => {
            let data = result.data;
            if (data.update && data.wgtUrl) {
              // 去服务端下载资源
              uni.downloadFile({
                url: data.wgtUrl,
                success: res1 => {
                  if (res1.statusCode === 200) {
                    // 更新包文件
                    plus.runtime.install(res1.tempFilePath, {
                      force: false
                    }, () => {
                      console.log("下载成功了")
                      // 重启设备
                      plus.runtime.restart()
                    }, err => {
                      console.error("下载失败了")
                    })

                  }
                }
              });
            }
          }
        });
      });
      // #endif
    })
  };
</script>

</html>